import type { RouteRecordRaw } from 'vue-router'
import MainLayout from '@/layout/MainLayout.vue'

/**
 * 公共路由 - 所有角色都可以访问
 */
export const constantRoutes: RouteRecordRaw[] = [
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/Login.vue'),
    meta: {
      hidden: true // 在菜单中隐藏
    }
  },
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/home',
    component: MainLayout,
    children: [
      {
        path: '',
        name: 'home',
        component: () => import('@/views/HomeView.vue'),
        meta: {
          title: '系统首页',
          icon: 'House',
          requiresAuth: true
        }
      }
    ]
  },
  {
    path: '/404',
    name: '404',
    component: () => import('@/views/error-page/404.vue'),
    meta: {
      hidden: true
    }
  }
]

/**
 * 异步路由 - 需要根据用户角色动态添加的路由
 */
export const asyncRoutes: RouteRecordRaw[] = [
  // 客户档案
  {
    path: '/base/users',
    component: MainLayout,
    name: '客户档案',
    meta: {
      title: '客户档案',
      icon: 'User'
    },
    children: [
      {
        path: '',
        name: 'users',
        component: () => import('@/views/users/UsersList.vue'),
        meta: { title: '客户档案', icon: 'User' }
      }
    ]
  },
  
  // 宠物档案
  {
    path: '/base/pets',
    component: MainLayout,
    name: '宠物档案',
    meta: {
      title: '宠物档案',
      icon: 'Pet'
    },
    children: [
      {
        path: '',
        name: 'pets',
        component: () => import('@/views/pets/PetsList.vue'),
        meta: { title: '宠物档案', icon: 'Pet' }
      }
    ]
  },
  
  // 疫苗接种记录
  {
    path: '/medical-manage/vaccine',
    component: MainLayout,
    name: '疫苗接种记录',
    meta: {
      title: '疫苗接种记录',
      icon: 'Vaccine'
    },
    children: [
      {
        path: '',
        name: 'vaccine',
        component: () => import('@/views/vaccine/VaccineList.vue'),
        meta: { title: '疫苗接种记录', icon: 'Vaccine' }
      }
    ]
  },
  
  // 驱虫记录
  {
    path: '/medical-manage/dewormings',
    component: MainLayout,
    name: '驱虫记录',
    meta: {
      title: '驱虫记录',
      icon: 'Deworming'
    },
    children: [
      {
        path: '',
        name: 'dewormings',
        component: () => import('@/views/dewormings/DewormingsList.vue'),
        meta: { title: '驱虫记录', icon: 'Deworming' }
      }
    ]
  },
  
  // 疾病史
  {
    path: '/medical-manage/medical',
    component: MainLayout,
    name: '疾病史',
    meta: {
      title: '疾病史',
      icon: 'FirstAidKit'
    },
    children: [
      {
        path: '',
        name: 'medical',
        component: () => import('@/views/medical/MedicalList.vue'),
        meta: { title: '疾病史', icon: 'FirstAidKit' }
      }
    ]
  },
  
  // 体检记录
  {
    path: '/medical-manage/checkups',
    component: MainLayout,
    name: '体检记录',
    meta: {
      title: '体检记录',
      icon: 'FirstAidKit'
    },
    children: [
      {
        path: '',
        name: 'checkups',
        component: () => import('@/views/checkups/CheckupsList.vue'),
        meta: { title: '体检记录', icon: 'FirstAidKit' }
      }
    ]
  },
  
  // 服务项目
  {
    path: '/system/services',
    component: MainLayout,
    name: '服务项目',
    meta: {
      title: '服务项目',
      icon: 'Service'
    },
    children: [
      {
        path: '',
        name: 'services',
        component: () => import('@/views/services/ServicesList.vue'),
        meta: { title: '服务项目', icon: 'Service' }
      }
    ]
  },
  
  // 服务人员
  {
    path: '/system/staffs',
    component: MainLayout,
    name: '服务人员',
    meta: {
      title: '服务人员',
      icon: 'User'
    },
    children: [
      {
        path: '',
        name: 'staffs',
        component: () => import('@/views/staffs/StaffsList.vue'),
        meta: { title: '服务人员', icon: 'User' }
      }
    ]
  },
  
  // 服务资源
  {
    path: '/system/resources',
    component: MainLayout,
    name: '服务资源',
    meta: {
      title: '服务资源',
      icon: 'Box'
    },
    children: [
      {
        path: '',
        name: 'resources',
        component: () => import('@/views/resources/ResourcesList.vue'),
        meta: { title: '服务资源', icon: 'Box' }
      }
    ]
  },
  
  // 预约记录
  {
    path: '/base/appointments',
    component: MainLayout,
    name: '预约记录',
    meta: {
      title: '预约记录',
      icon: 'Calendar'
    },
    children: [
      {
        path: '',
        name: 'appointments',
        component: () => import('@/views/appointments/AppointmentsList.vue'),
        meta: { title: '预约记录', icon: 'Calendar' }
      }
    ]
  },
  
  // 服务记录
  {
    path: '/biz-manage/service-records',
    component: MainLayout,
    name: '服务记录',
    meta: {
      title: '服务记录',
      icon: 'Document'
    },
    children: [
      {
        path: '',
        name: 'service-records',
        component: () => import('@/views/service-records/ServiceRecordsList.vue'),
        meta: { title: '服务记录', icon: 'Document' }
      }
    ]
  },
  
  // 表单页面 - 作为顶层路由，使用 MainLayout
  { path: '/users/add', component: MainLayout, meta: { hidden: true }, children: [{ path: '', name: 'users-add', component: () => import('@/views/users/UsersForm.vue'), meta: { title: '添加客户' } }] },
  { path: '/users/update/:id', component: MainLayout, meta: { hidden: true }, children: [{ path: '', name: 'users-edit', component: () => import('@/views/users/UsersForm.vue'), meta: { title: '编辑客户' } }] },
  { path: '/pets/add', component: MainLayout, meta: { hidden: true }, children: [{ path: '', name: 'pets-add', component: () => import('@/views/pets/PetsForm.vue'), meta: { title: '添加宠物' } }] },
  { path: '/pets/update/:id', component: MainLayout, meta: { hidden: true }, children: [{ path: '', name: 'pets-edit', component: () => import('@/views/pets/PetsForm.vue'), meta: { title: '编辑宠物' } }] },
  { path: '/services/add', component: MainLayout, meta: { hidden: true }, children: [{ path: '', name: 'services-add', component: () => import('@/views/services/ServicesForm.vue'), meta: { title: '添加服务' } }] },
  { path: '/services/update/:id', component: MainLayout, meta: { hidden: true }, children: [{ path: '', name: 'services-edit', component: () => import('@/views/services/ServicesForm.vue'), meta: { title: '编辑服务' } }] },
  { path: '/appointments/add', component: MainLayout, meta: { hidden: true }, children: [{ path: '', name: 'appointments-add', component: () => import('@/views/appointments/AppointmentsForm.vue'), meta: { title: '添加预约' } }] },
  { path: '/appointments/update/:id', component: MainLayout, meta: { hidden: true }, children: [{ path: '', name: 'appointments-edit', component: () => import('@/views/appointments/AppointmentsForm.vue'), meta: { title: '编辑预约' } }] },
  { path: '/medical/add', component: MainLayout, meta: { hidden: true }, children: [{ path: '', name: 'medical-add', component: () => import('@/views/medical/MedicalForm.vue'), meta: { title: '添加就诊记录' } }] },
  { path: '/medical/update/:id', component: MainLayout, meta: { hidden: true }, children: [{ path: '', name: 'medical-edit', component: () => import('@/views/medical/MedicalForm.vue'), meta: { title: '编辑就诊记录' } }] },
  { path: '/checkups/add', component: MainLayout, meta: { hidden: true }, children: [{ path: '', name: 'checkups-add', component: () => import('@/views/checkups/CheckupsForm.vue'), meta: { title: '添加体检记录' } }] },
  { path: '/checkups/update/:id', component: MainLayout, meta: { hidden: true }, children: [{ path: '', name: 'checkups-edit', component: () => import('@/views/checkups/CheckupsForm.vue'), meta: { title: '编辑体检记录' } }] },
  { path: '/vaccine/add', component: MainLayout, meta: { hidden: true }, children: [{ path: '', name: 'vaccine-add', component: () => import('@/views/vaccine/VaccineForm.vue'), meta: { title: '添加疫苗记录' } }] },
  { path: '/vaccine/update/:id', component: MainLayout, meta: { hidden: true }, children: [{ path: '', name: 'vaccine-edit', component: () => import('@/views/vaccine/VaccineForm.vue'), meta: { title: '编辑疫苗记录' } }] },
  { path: '/dewormings/add', component: MainLayout, meta: { hidden: true }, children: [{ path: '', name: 'dewormings-add', component: () => import('@/views/dewormings/DewormingsForm.vue'), meta: { title: '添加驱虫记录' } }] },
  { path: '/dewormings/update/:id', component: MainLayout, meta: { hidden: true }, children: [{ path: '', name: 'dewormings-edit', component: () => import('@/views/dewormings/DewormingsForm.vue'), meta: { title: '编辑驱虫记录' } }] },
  { path: '/staffs/add', component: MainLayout, meta: { hidden: true }, children: [{ path: '', name: 'staffs-add', component: () => import('@/views/staffs/StaffsForm.vue'), meta: { title: '添加人员' } }] },
  { path: '/staffs/update/:id', component: MainLayout, meta: { hidden: true }, children: [{ path: '', name: 'staffs-edit', component: () => import('@/views/staffs/StaffsForm.vue'), meta: { title: '编辑人员' } }] },
  { path: '/resources/add', component: MainLayout, meta: { hidden: true }, children: [{ path: '', name: 'resources-add', component: () => import('@/views/resources/ResourcesForm.vue'), meta: { title: '添加资源' } }] },
  { path: '/resources/update/:id', component: MainLayout, meta: { hidden: true }, children: [{ path: '', name: 'resources-edit', component: () => import('@/views/resources/ResourcesForm.vue'), meta: { title: '编辑资源' } }] },
  { path: '/service-records/add', component: MainLayout, meta: { hidden: true }, children: [{ path: '', name: 'service-records-add', component: () => import('@/views/service-records/ServiceRecordsForm.vue'), meta: { title: '添加服务记录' } }] },
  { path: '/service-records/update/:id', component: MainLayout, meta: { hidden: true }, children: [{ path: '', name: 'service-records-edit', component: () => import('@/views/service-records/ServiceRecordsForm.vue'), meta: { title: '编辑服务记录' } }] },

  // 个人信息页面
  {
    path: '/user/profile',
    name: 'profile',
    component: () => import('@/views/user/Profile.vue'),
    meta: { title: '个人信息', icon: 'User', hidden: true }
  },

  // 404页面必须放在最后
  {
    path: '/:pathMatch(.*)*',
    redirect: '/404',
    meta: {
      hidden: true
    }
  }
] 